<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of rgbConvert</title>
  <meta name="keywords" content="rgbConvert">
  <meta name="description" content="Convert RGB image to other color spaces (highly optimized).">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html channels -->
<h1>rgbConvert
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Convert RGB image to other color spaces (highly optimized).</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function J = rgbConvert( I, colorSpace, useSingle ) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Convert RGB image to other color spaces (highly optimized).

 If colorSpace=='gray' transforms I to grayscale. The output is within
 numerical error of Matlab's rgb2gray, except ~10x faster. The output in
 this case is hxwx1, and while the input must be hxwx3 for all other
 cases, the input for this case can also be hxwx1 (normalization only).

 If colorSpace=='hsv' transforms I to the HSV color space. The output is
 within numerical error of Matlab's rgb2hsv, except ~15x faster.

 If colorSpace=='rgb' or colorSpace='orig' only normalizes I to be in the
 range [0,1]. In this case both the input and output may have an arbitrary
 number of channels (that is I may be [hxwxd] for any d).

 If colorSpace=='luv' transforms I to the LUV color space. The LUV color
 space is &quot;perceptually uniform&quot; (meaning that two colors equally distant
 in the color space according to the Euclidean metric are equally distant
 perceptually). The L,u,v channels correspond roughly to luminance,
 green-red, blue-yellow. For more information see:
   http://en.wikipedia.org/wiki/CIELUV - using this color spaces
   http://en.wikipedia.org/wiki/CIELAB - more info about color spaces
 The LUV channels are normalized to fall in ~[0,1]. Without normalization
 the ranges are L~[0,100], u~[-88,182], and v~[-134,105] (and typically
 u,v~[-100,100]). The applied transformation is L=L/270, u=(u+88)/270, and
 v=(v+134)/270. This results in ranges L~[0,.37], u~[0,1], and v~[0,.89].
 Perceptual uniformity is maintained since divisor is constant
 (normalizing each color channel independently would break uniformity).
 To undo the normalization on an LUV image J use:
   J=J*270; J(:,:,2)=J(:,:,2)-88; J(:,:,3)=J(:,:,3)-134;
 To test the range of the colorSpace use:
   R=100; I=zeros(R^3,1,3); k=1; R=linspace(0,1,R);
   for r=R, for g=R, for b=R, I(k,1,:)=[r g b]; k=k+1; end; end; end
   J=rgbConvert(I,'luv'); [min(J), max(J)]

 This code requires SSE2 to compile and run (most modern Intel and AMD
 processors support SSE2). Please see: http://en.wikipedia.org/wiki/SSE2.

 USAGE
  J = rgbConvert( I, colorSpace, [useSingle] );

 INPUTS
  I          - [hxwx3] input rgb image (uint8 or single/double in [0,1])
  colorSpace - ['luv'] other choices include: 'gray', 'hsv', 'rgb', 'orig'
  useSingle  - [true] determines output type (faster if useSingle)

 OUTPUTS
  J          - [hxwx3] single or double output image (normalized to [0,1])

 EXAMPLE - luv
  I = imread('peppers.png');
  tic, J = rgbConvert( I, 'luv' ); toc
  figure(1); montage2( J );

 EXAMPLE - hsv
  I=imread('peppers.png');
  tic, J1=rgb2hsv( I ); toc
  tic, J2=rgbConvert( I, 'hsv' ); toc
  mean2(abs(J1-J2))

 EXAMPLE - gray
  I=imread('peppers.png');
  tic, J1=rgb2gray( I ); toc
  tic, J2=rgbConvert( I, 'gray' ); toc
  J1=single(J1)/255; mean2(abs(J1-J2))

 See also rgb2hsv, rgb2gray

 Piotr's Computer Vision Matlab Toolbox      Version 3.02
 Copyright 2014 Piotr Dollar &amp; Ron Appel.  [pdollar-at-gmail.com]
 Licensed under the Simplified BSD License [see external/bsd.txt]</pre></div>





<!-- Start of Google Analytics Code -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4884268-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- end of Google Analytics Code -->

<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>
